package com.umasuo.uclient;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.Window;
import android.view.WindowManager;
import android.webkit.JsResult;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings.ZoomDensity;
import android.webkit.WebView;

import com.umasuo.uclient.util.JSInterface;

/**
 * An example full-screen activity that shows and hides the system UI (i.e.
 * status bar and navigation/system bar) with user interaction.
 * 
 * @see SystemUiHider
 */
public class MainActivity extends Activity {
	
	private String version;//客户端的当前版本。
	private String uId;//这个客户端所属的用户，平台的用户账号
	private WebView mWebView ;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
		setContentView(R.layout.activity_main);

		mWebView = (WebView)findViewById(R.id.fullscreen_content);
		
		loadWebViewSetting();//这里加载webView的设置
		mWebView.loadUrl("file:///android_asset/www/index.html");//在这里load我们自己的主页
	}
	/**
	 * 在这里加载和webview有关的一些配置。
	 */
	private void loadWebViewSetting(){
		if(mWebView == null){
			return;
		}
//		   WebSettings webSettings = mWebView.getSettings();
//	       webSettings.setSavePassword(true);
//	       webSettings.setAppCacheEnabled(true);
//	       webSettings.setDatabaseEnabled(true);//允许使用数据库
//	       webSettings.setSaveFormData(false);
//	       webSettings.setJavaScriptEnabled(true);
//	       webSettings.setSupportZoom(false);
		mWebView.getSettings().setJavaScriptEnabled(true);//允许JS执行
		mWebView.addJavascriptInterface(JSInterface.instance, "umasuo");//建立和JS交互的接口
		mWebView.getSettings().setLoadWithOverviewMode(true);//
	//	mWebView.getSettings().setBuiltInZoomControls(true);
	    mWebView.setWebChromeClient(new MyWebChromeClient());
	    //下面两个是取消掉滚轮，并取消的话，旁边就会为滚轮留下一条白色的预留位置，取消才能够让页面100%的展示，因为游戏界面只有一个画面，所以一屏足够
	    mWebView.setVerticalScrollBarEnabled(false);
	    mWebView.setHorizontalScrollBarEnabled(false);
	}
	
	
    /**
     * Provides a hook for calling "alert" from javascript. Useful for
     * debugging your javascript.
     */
    final class MyWebChromeClient extends WebChromeClient {
        @Override
        public boolean onJsAlert(WebView view, String url, String message, JsResult result) {
            Log.d("JSInterface", message);
            result.confirm();
            return true;
        }
    }
    

}
